package org.erp.admins.controller;

import org.erp.admins.infrastructure.convert.SalesChannelsConvert;
import org.erp.admins.domain.bo.SalesChannelsBo;
import org.erp.admins.domain.dto.SalesChannelsDto;
import org.erp.admins.domain.vo.SalesChannelsVo;
import org.erp.admins.service.SalesChannelsService;
import org.erp.common.page.DataPageResp;
import org.erp.common.page.PageQueryModel;
import org.erp.common.domain.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

import static org.erp.common.domain.Result.success;
/**
 * 销售渠道信息控制层
 *
 * @author dingding
 * @since 2025-11-24 16:47:44
 */
@RestController
@RequestMapping("/sales/channels")
public class SalesChannelsController {
    @Resource
    private SalesChannelsService salesChannelsService;

    @Resource
    private SalesChannelsConvert salesChannelsConvert;
    /**
     * 分页查询所有数据
     *
     * @param bo 筛选条件
     * @return 所有数据
     */
    @GetMapping("/getListByPage")
    public Result<DataPageResp<SalesChannelsVo>> getListByPage(SalesChannelsBo bo) {
        SalesChannelsDto dto = salesChannelsConvert.boConvertDto(bo);
        PageQueryModel<SalesChannelsVo> qm = salesChannelsService.getListByPage(dto);
        return success(DataPageResp.of(qm.getTotal(), qm.getDataList()));
    }
    /**
     * 查询所有数据
     *
     * @param bo 筛选条件
     * @return 所有数据
     */
    @GetMapping("/getList")
    public Result<List<SalesChannelsVo>> getList(SalesChannelsBo bo) {
        SalesChannelsDto dto = salesChannelsConvert.boConvertDto(bo);
        return Result.success(salesChannelsService.getSalesChannelsVoList(dto));
    }
    /**
     * 通过id查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public Result<SalesChannelsVo> selectOne(@PathVariable Long id) {
        return Result.success(salesChannelsService.getSalesChannelsVoById(id));
    }
    /**
     * 新增数据
     *
     * @param dto 实体
     * @return 新增结果
     */
    @PostMapping("/add")
    public Result<Boolean> insert(@RequestBody SalesChannelsDto dto) {
        boolean result = salesChannelsService.addSalesChannels(dto);
        return result ? Result.success("新增成功") : Result.error("新增失败");
    }
    /**
     * 修改数据
     *
     * @param dto 实体
     * @return 修改结果
     */
    @PostMapping("/upd")
    public Result<Boolean> update(@RequestBody SalesChannelsDto dto) {
        boolean result = salesChannelsService.updSalesChannels(dto);
        return result ? Result.success("修改成功") : Result.error("修改失败");
    }
    /**
     * 删除数据
     *
     * @param bo 主键
     * @return 删除结果
     */
    @PostMapping("/del")
    public Result<Boolean> delete(@RequestBody SalesChannelsBo bo) {
        boolean result = salesChannelsService.removeById(bo.getId());
        return result ? Result.success("删除成功") : Result.error("删除失败");
    }
}

